#include <stack>
#include <vector>
using namespace std;

class Solution
{
public:
    static bool validateStackSequences(const vector<int>& pushed, const vector<int>& popped)
    {
        stack<int> st;
        int pushi = 0, popi = 0;
        while(pushi < pushed.size())
        {
            st.push(pushed[pushi]);
            while(!st.empty() && st.top() == popped[popi])
            {
                st.pop();
                popi++;
            }
            pushi++;
        }
        return st.empty();
    }
};